package com.wanlian.router.ui.main.yun;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.smart.android.ui.tools.MyNiuBAdapter;
import com.smart.android.utils.DateTime;
import com.wanlian.router.R;
import com.wanlian.router.bean.YunFile;

import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/9/3.
 * Email: fvaryu@qq.com
 */
public class YunVideoAdapter extends MyNiuBAdapter<YunFile> {

    private OnItemClickListener mOnItemClickListener;

    public YunVideoAdapter(Context context, List<YunFile> mTs) {
        super(context, mTs);
    }

    public void setOnItemClickListener(YunVideoAdapter.OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    @Override
    public int layout() {
        return R.layout.layout_item_yun_video;
    }

    @Override
    public MyViewHolder<YunFile> holder(View view) {
        return new YunMusicHolder(view);
    }

    public interface OnItemClickListener {
        void onItemClick(MoreDialog.Op op, int pos);
    }

    class YunMusicHolder extends MyViewHolder<YunFile> {

        @BindView(R.id.tv_name)
        TextView mName;
        @BindView(R.id.tv_time)
        TextView mTime;
        @BindView(R.id.image_more)
        ImageView more;

        public YunMusicHolder(View view) {
            super(view);
        }

        @Override
        public void setData(int i, YunFile yunVideo) {
            mName.setText(yunVideo.getFileName());
            mTime.setText(String.format(Locale.getDefault(),
                    "%s  %s", yunVideo.getUISize(), DateTime.getDateByType(yunVideo.getUploadTime(), "yyyy/MM/dd HH:mm")));

            more.setTag(i);
        }

        @OnClick(R.id.image_more)
        void more(final View view) {
            final int p = (int) view.getTag();
            MoreDialog dialog = new MoreDialog(view.getContext());
            dialog.setOnItemClickListener(new MoreDialog.OnItemClickListener() {
                @Override
                public void onItemClick(MoreDialog.Op op) {
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onItemClick(op, p);
                    }
                }
            });
            YunFile file = getItem(p);
            dialog.setTitle(file.getFileName());
            dialog.show();
        }

    }
}
